﻿@* --------------------------------------------------------------------------------------------------------------------
// <copyright file="BaseLayout.cshtml" company="Devbridge Group LLC">
// 
// Copyright (C) 2015,2016 Devbridge Group LLC
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see http://www.gnu.org/licenses/. 
// </copyright>
// 
// <summary>
// Better CMS is a publishing focused and developer friendly .NET open source CMS.
// 
// Website: https://www.bettercms.com 
// GitHub: https://github.com/devbridge/bettercms
// Email: info@bettercms.com
// </summary>
// -------------------------------------------------------------------------------------------------------------------- *@
@using BetterCms.Module.Root.Mvc
@using BetterCms.Module.Root.Mvc.Helpers
@using BetterCms.Module.Root.ViewModels.Cms

@model RenderPageViewModel
@{
    Layout = "RootLayout.cshtml";
}

@if (Model.CanManageContent)
{
    @Html.Partial("~/Areas/bcms-root/Views/Shared/Partial/SupportBrowser.cshtml")
    @Html.Partial("~/Areas/bcms-root/Views/Shared/Partial/SupportJavascript.cshtml")
    @Html.Partial("~/Areas/bcms-root/Views/Shared/Partial/MasterPagesPath.cshtml")
}

@RenderBody()

@section CmsMetaTitle {
    <title>@Model.MetaTitle</title>
}

@section CmsMeta {    
    @if (Model.Metadata != null)
    {
        foreach (var metaData in Model.Metadata)
        {
            metaData.Render(Model, (ViewContext.Controller as CmsControllerBase).SecurityService, Html);
        }
    }
}
@section CmsHeadStyles {   
    @if (Model.CanManageContent)
    {
        @Html.Action("RenderStyleSheetIncludes", "Rendering")
    }
}

@section CmsHeadScripts {
    @RenderSection("CmsHeadScripts", false)

    @if (Model.CanManageContent)
    {
        <script type="text/javascript">
            function loadBetterCmsScriptAsync(url, callback) {
                var head = document.getElementsByTagName("head")[0];
                var scriptTag = document.createElement("script");
                scriptTag.type = 'text/javascript';
                scriptTag.src = url;
                scriptTag.async = true;

                // Attach handlers for all browsers
                var done = false;
                scriptTag.onload = scriptTag.onreadystatechange = function() {
                    if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
                        done = true;
                        try {
                            if (callback) {
                                callback();
                            }
                        } finally {
                            scriptTag.onload = scriptTag.onreadystatechange = null;
                            head.removeChild(scriptTag);
                        }
                    }
                };

                head.appendChild(scriptTag);
            }

            (function() {
                loadBetterCmsScriptAsync('@Model.RequireJsPath', function() {
                    loadBetterCmsScriptAsync('@Model.MainJsPath');
                });
            })();
        </script>
        <!--[if lt IE 9]>
            <script src="@Model.Html5ShivJsPath"></script>
        <![endif]-->
    }
}

@section CmsScripts {
    @if (Model.CanManageContent)
    {
        @Html.Partial("Partial/Region")
        @Html.Partial("Partial/ContentOverlay")
        @Html.Action("Container", "Sidebar", Model)
        @Html.Partial("Partial/Modal")
        @Html.Partial("Partial/Alert")
        @Html.Partial("Partial/Confirm")
        @Html.Partial("Partial/Delete")
        @Html.Partial("Partial/Info")
        @Html.Partial("Partial/Tooltip")
        @Html.Partial("Partial/ImagePreview")
        @Html.Partial("Partial/SiteSettingTab")
        @Html.Partial("Partial/ContentsTree")
    }

    @if (Model.JavaScripts != null)
    {
        @Html.RenderPageCustomJavaScript(Model.JavaScripts, Model)
    }
}

@section Styles {
    @RenderSection("Styles", false)

    @if (Model.Stylesheets != null)
    {
        @Html.RenderPageCustomCss(Model.Stylesheets, Model)
    }
}
@section HeadScripts {
    @RenderSection("HeadScripts", false)
}
@section Scripts {
    @RenderSection("Scripts", false)
}
@section DoctypeTag { 
    @if (IsSectionDefined("DoctypeTag"))
    {
        @RenderSection("DoctypeTag", false)
    }
    else
    {
        @:<!DOCTYPE html>
    }
}
@section HtmlTag { 
    @if (IsSectionDefined("HtmlTag"))
    {
        @RenderSection("HtmlTag", false)
    }
    else
    {
        @:<html>
    }
}
@section BodyTag { 
    @if (IsSectionDefined("BodyTag"))
    {
        @RenderSection("BodyTag", false)
    }
    else
    {
        @:<body @Html.RenderBodyAttributes()@RenderSection("BodyAttributes", false)>
    }
}
